package cn.itcast.work.dao.system;


import cn.itcast.work.pojo.TextWhole;
import cn.itcast.work.pojo.Text_show;
import cn.itcast.work.pojo.User;
import cn.itcast.work.pojo.User_show;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface SystemMapper {

    /**
     * 后台系统
     * 1.对于博客的操作
     * 2.对于用户的操作
     */

    //1.查询所有
    @Select("select phone, title, subtitle, content, createdate, cid, mid from text")
    public List<TextWhole> selectAll();

    //插入 推送博客
    @Insert("insert into home_page (title, phone) values (#{title}, #{phone})")
    public int insertText(@Param("phone") String phone, @Param("title") String title);

    //删除博客
    @Delete("delete from text where title=#{title} and phone=#{phone}")
    public int deleteText(@Param("phone") String phone, @Param("title") String title);

    //撤销
    @Delete("delete from home_page where title=#{title}")
    public int cancelText(@Param("title") String title);

    //显示首页表 main.jsp
    @Select("select userName, text.phone, text.title, text.subtitle, text.content, text.createdate, cname, " +
            "mname from text join users on users.phone=text.phone join aCategory on aCategory.id=text.mid " +
            "join category2 on" +
            " category2.id=text.cid where text.put=1")
    public List<Text_show> selectPutText();

    //查询 homepage中的表
    @Select("select title from home_page")
    public List<String> selectPutTitle();

    //2.查询所有用户role=2
    @Select("select * from users where role=2")
    public List<User> selectAllUser();

    //推送 用户
    @Insert("insert into home_user (name, phone) values (#{username}, #{phone})")
    public int insertUser(@Param("phone") String phone, @Param("username") String username);

    //撤销用户
    @Delete("delete from home_user where name=#{name}")
    public int cancelUser(@Param("name") String name);

    //显示推荐用户
    @Select("select * from users where put=1")
    public List<User> selectPutUser();


}
